﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Service4u2.Json;
using Service4u2.Common;

namespace Service4u2.Example.Services
{
    // example rest json url: http://www.flickr.com/services/rest/?method=flickr.test.echo&format=json&api_key=6fa73ab8e019955049ffb7f2ed7b218b&nojsoncallback=1

    // flickr has a weird wrapped content thing
    public class FlickrJsonContent<TContent>
    {
        public TContent _content { get; set; }
    }

    /// <summary>
    /// Create the result model.
    /// </summary>
    public class FlickrEchoResult
    {
        // Example of response.
        // {"method":{"_content":"flickr.test.echo"}, "format":{"_content":"json"}, "api_key":{"_content":"6fa73ab8e019955049ffb7f2ed7b218b"}, "nojsoncallback":{"_content":"1"}, "stat":"ok"}
        public FlickrJsonContent<string> method { get; set; }
        public FlickrJsonContent<string> format { get; set; }
        public FlickrJsonContent<string> api_key { get; set; }
        public string stat { get; set; }
    }

    /// <summary>
    /// An example service that calls the flickr rest api echo method.
    /// </summary>
    public class FlickrEchoService : BaseJsonService<FlickrEchoResult>
    {
        
        public void StartFlickrEchoAsync()
        {
            var flickrEchoUrl = "http://www.flickr.com/services/rest/?method=flickr.test.echo&format=json&api_key=6fa73ab8e019955049ffb7f2ed7b218b&nojsoncallback=1";
            
            StartServiceCall(flickrEchoUrl, HttpMethod.GET);
        }
    }
}
